<?php 
defined('BASEPATH') OR exit('No direct script access allowed');

class Details extends Auth_Controller{
	
	public function __construct(){
		parent::__construct();
		$this->load->model('details_mdl','det_mdl');
	}
	
	
	/**
	 * 商品详情修改
	 */
	public function update(){
		$gid = $this->input->get('gid',TRUE);
		
		if(empty($gid)){
			show_404();
			exit;
		}
		
		$this->db->select('id,content');
		$this->db->where('id',$gid);
		$res = $this->det_mdl->get_one();
		
		if(empty($res)){
			show_error('参数错误！');
			exit;
		}
		
		$mess = $this->input->get('mess');
		$mess = empty($mess) ? '0' : $mess; 
		$this->_view('admin/details_update',['res'=>$res,'mess'=>$mess]);
	}
	
	/**
	 * 修改
	 */
	public function setdet(){
		$post = $this->input->post(NULL,TRUE);
		if(empty($post['id'])){
			show_error('参数错误！');
			exit;
		}
		
		$post['action_time'] = $_SERVER['REQUEST_TIME'];
		$post['action_user'] = $this->session->userdata('id');
		
		$this->db->where('id',$post['id']);
		$r = $this->det_mdl->update($post);
		$this->logs->add($r,'更新商品详情内容');
		$r = $r === false ? '更新失败！':1;
		redirect(site_url('admini/details/update?gid='.$post['id'].'&mess='.$r));
	}
}
